<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;

class UserInfoRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(Request $request)
    {
        $user_id = $request->user->id;

        return [
            'avatar' => 'required',
            'nickname' => 'required|between:3,25|unique:users,nickname,' . $user_id,
            'personal_signature' => 'required|between:1,30',
        ];
    }

    public function messages()
    {
        return [
            'avatar.required' => '请选择头像',

            'nickname.required' => '昵称不能为空',
            'nickname.between' => '昵称必须介于 3 - 25 个字符之间',
            'nickname.unique' => '该昵称已经被占用',

            'personal_signature.required' => '个性签名不能为空',
            'personal_signature.between' => '个性签名必须介于 1 - 30 个字符之间',
        ];
    }
}
